<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">

    <h:head>
        <title>#{msgPool['system.homeName']}</title>

        <link type="text/css" rel="stylesheet" href="#{request.contextPath}/css/default.css" />
        <link type="text/css" rel="stylesheet" href="#{request.contextPath}/themes/black-tie/skin.css" />
        <script type="text/javascript" src="#{request.contextPath}/js/padrao.js"></script>

        <style type="text/css">
            * { margin: 0; padding: 0; z-index: 1; }
            #limites { position: absolute; top: 40%; left: 45%; width: 700px; height: auto; margin: -200px 0 0 -340px; 
                       background-color: #eee; padding: 20px; }
        </style>

        <script type="text/javascript"> 
            function checkUserCode() {
              if (jQuery('input[id*="username"]').val() === '') {
                growl.renderMessage({summary: "#{msgLogin['I007']}", detail: "#{msgLogin['W001']}", severity: 0});
              }
              else {
                dlgAltrSenha.show();
              }
            }
            function socketNotificationsMessages(facesmessage) {
                if (facesmessage !== null) {
                    <!-- Não fornecido em LoginBean: pushContext.push("/notifications", facesMessage) -->
                    <!-- growl.show([facesmessage]); -->
                }
                AbreJanela(false); 
            }      
            function handleLoginRequest(xhr, status, args) {  
                if(args.validationFailed || !args.loggedIn) {  
                    dlgAltrSenha.show();
                    dlgAltrSenha.jq.effect("shake", { times:5 }, 100);  
                }   
                else {  
                    dlgAltrSenha.hide();
                }  
            }          
        </script>  
    </h:head>
    
    <h:body>
        <h:form id="loginForm"> 
                
            <div id="limites">
                <p:growl id="growl" widgetVar="growl" showDetail="true" life="5000" severity="info" />
                <p:messages id="messages" globalOnly="true" showDetail="true" autoUpdate="true" closable="true" severity="warn, error" />
                <p:socket onMessage="socketNotificationsMessages" channel="/notifications" />

                <p:menubar id="opcaoSenhas"> 
                    <p:menuitem value="#{msgLogin['I012']}" url="#" icon="ui-icon-wrench" onclick="checkUserCode();" />  
                    <p:menuitem value="#{msgLogin['I013']}" url="/seguranca/recuperar_senha.jsf" icon="ui-icon-alert" rendered="true" />  
                </p:menubar>     

                <p:panel id="loginPanel" header="#{msgLogin['I001']}" style="text-align: center" >  
                    
                    <p:focus for="username" />
                    <div align="center">
                        <br /><br />
                  
                        <h:panelGrid columns="3">       
                            <h:outputLabel for="username" value="#{msgLogin['I007']}: *" style="float:right"/>
                            <p:inputText id="username" value="#{loginBean.username}" 
                                         required="true" label="#{msgLogin['I007']}" >
                            </p:inputText> 
                            <p:message for="username" display="icon"/> 
                            
                            <h:outputLabel for="password" value="#{msgLogin['I008']}: *" style="float:right"/>
                            <p:password id="password" value="#{loginBean.password}"  
                                        required="true" label="#{msgLogin['I008']}" >
                            </p:password> 
                            <p:message for="password" display="icon"/>       
                        </h:panelGrid>       
                        
                        <br />  
                        <h:panelGrid columns="2" >
                            <h:outputLabel for="idioma" value="#{msgLogin['I010']}:&nbsp;&nbsp;" style="float:right"/> 
                            <p:selectOneMenu id="idioma" value="#{languageBean.localeCode}" label="#{msgLogin['I010']}" 
                                             valueChangeListener="#{languageBean.alteraLocaleCodePaises}" >
                                <p:ajax update="opcaoSenhas,loginPanel" process="@this" />  
   			        <f:selectItems value="#{languageBean.mapPaises}" /> 
   		            </p:selectOneMenu>                                
                        </h:panelGrid>
                        
                        <br /><br /> 
                        <h:panelGrid>
                            <p:commandButton value="#{msgLogin['I011']}" actionListener="#{loginBean.login}"
                                             update="loginPanel" icon="ui-icon-person" 
                                             onclick="javascript:AbreJanela(true);" />
                        </h:panelGrid>

                        <!-- p:separator / -->
                        <div id="conexao" name="conexao" style="visibility:hidden" align="center">
                            <p:fieldset legend="#{msgPool['geral.I002']}">
                                <img src="images/comunicacao.gif" width="200" height="100"/>
                            </p:fieldset>
                        </div>
                        
                    </div>
                </p:panel>
                
                <p:dialog id="dialogAltr" header="#{msgLogin['I012']}" widgetVar="dlgAltrSenha" closable="false"
                          draggable="false" resizable="false" width="570" height="175" hideEffect="explode" >  
                    
                    <h:panelGrid columns="3">  
                        <h:outputLabel for="senhavelha" value="#{msgLogin['I009']}: *" style="float:right" />  
                        <p:password id="senhavelha" value="#{loginBean.password}" />
                        <p:message for="senhavelha" display="text" />  
                                  
                        <h:outputLabel for="senhanova" value="#{msgLogin['I014']}: *" style="float:right"/>  
                        <p:password id="senhanova" value="#{loginBean.newPassword}" 
                                    feedback="true" label="#{msgLogin['I014']}"
                                    promptLabel="#{msgLogin['I002']}" weakLabel="#{msgLogin['I003']}"  
                                    goodLabel="#{msgLogin['I004']}" strongLabel="#{msgLogin['I005']}" >
                        </p:password>   
                        <p:message for="senhanova" display="text" />  

                        <h:outputLabel for="confsenha" value="#{msgLogin['I015']}: *" style="float:right"/>  
                        <p:password id="confsenha" value="#{loginBean.confirmPassword}" label="#{msgLogin['I015']}" />  
                        <p:message for="confsenha" display="text" />    
                    </h:panelGrid>  
                    <br />
                    <h:panelGrid columns="2">
                        <p:commandButton value="#{msgPool['geral.I007']}" icon="ui-icon-disk" 
                                         update="growl,messages,dialogAltr"  
                                         process="@this,username,senhavelha,senhanova,confsenha"   
                                         oncomplete="handleLoginRequest(xhr, status, args)"
                                         actionListener="#{loginBean.alteraSenha}">
                        </p:commandButton> 
                        <p:commandButton value="#{msgPool['geral.I006']}" icon="ui-icon-close" 
                                         update="dialogAltr" process="@this" 
                                         onclick="dlgAltrSenha.hide();" >                      
                           <p:resetInput target="dialogAltr, messagesDialog" />
                        </p:commandButton>    
                    </h:panelGrid>
                    <p:messages id="messagesDialog" showDetail="true" closable="true" severity="warn"/>
                </p:dialog>  
                    
            </div>
        </h:form>
    </h:body>
</html>